$(document).ready(
    function() {
        showTipMsgs();
        obtainType();
        $("#licenseTemplate-id").on("change", function() {
            $("#licenseTemplate-type").val($(this).children('option:selected').text());
        });
        $("#inputForm")
            .validate(
                {
                    ignore: "",
                    submitHandler : function(form) {
                        form.submit();
                    },
                    errorElement:'div',
                    errorPlacement : function(error, element) {
                        $(element).parent().next().remove();
                        if (element.is(":checkbox")
                            || element.is(":radio")
                            || element.parent().is(
                                ".input-append")) {
                            error.appendTo(element.parent()
                                .parent());
                            $("<label class='wrong fa fa-times' style='margin-left: 5px;line-height: 34px'></label>").insertAfter(element.parent().parent().parent());
                        } else {
                            error.insertAfter(element);
                            $("<label class='wrong fa fa-times' style='margin-left: 5px;line-height: 34px'></label>").insertAfter(element.parent());
                        }
                    },
                    success: function(element) {
                        $(element).parent().next().removeClass('wrong fa fa-times');
                        $(element).parent().next().addClass('right fa fa-check');
                        $(element).remove();
                    },
                });
    });

function  renewalLicense() {
    console.log($('#inputForm').serialize());
    $.ajax({
        type: "POST",
        url:'../license/renewalLicese',
        async: false,
        data:$('#inputForm').serialize(),
        error: function(xml, obj) {
            console.log(xml);
            console.log(obj);
        },
        success: function(data) {
            var result = JSON.parse(data);
            if (result.isSuccess) {
                alert("license续期成功!");
                parent.window.location.reload();
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            } else {
                alert(result.msg);

            }
        }
    });
}

function obtainType(){
    $.ajax({
        url:'../license/license_licenseTemplate',
        async: false,
        dataType: "json",
        success:function(data) {
            con = "";
            for (var i in data) {
                if($("input[name='licenseTemplate.type']").val() == data[i].type){

                    con += "<option selected ='selected' value="+data[i].id+">"+data[i].type+"</option>";
                }else{
                    con += "<option value="+data[i].id+">"+data[i].type+"</option>";
                }
                $("#licenseTemplate-id").html(con);
            }
        }
    });
}

